import 'package:bruno/bruno.dart';
import 'package:flutter/cupertino.dart';

/**
 * 身份证验证
 */
import 'package:flutter/material.dart';
import 'package:flutter_boost/flutter_boost.dart';
import 'package:xiongmao_clean_flutter_module/business/common/approve/iview/approve_multiple_item_view.dart';
import 'package:xiongmao_clean_flutter_module/res/gaps.dart';
import 'package:xiongmao_clean_flutter_module/util/log_utils.dart';

import '../../../../res/colors.dart';
import '../../../../widgets/select_tab/select_tab_widget.dart';
import '../bean/base_choose_string.dart';
import '../iview/approve_user_item_view.dart';

/**
 * 设置入职审批的内容
 */
class AppSettingsMainPage extends StatefulWidget {
  final int position;

  AppSettingsMainPage({Key? key, this.position = 0}) : super(key: key);

  @override
  _AppSettingsMainPageState createState() => _AppSettingsMainPageState();
}

class _AppSettingsMainPageState extends State<AppSettingsMainPage> {
  int _nodeApprovalSelectedIndex = 0;
  int _nodeTypeSelectedIndex = 0;
  int _singleSelectedIndex = 0;

  List<String> _designatedSuperior = ["直属上级", "第二级上级", "第三级上级", "第四级上级", "第️五级上级", "第六级上级", "第七级上级", "第八级上级", "第九级上级", "第十级上级"];

  List<String> _roles = ["管理员", "人事", "项目负责人", "大区经理"];

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colours.base_primary_bg_page,
      appBar: BrnAppBar(
        title: '设置审批节点',
        backLeadCallback: () {
          BoostNavigator.instance.pop();
        },
      ),
      body: SingleChildScrollView(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            ///节点类型
            Container(
              padding: EdgeInsets.only(top: 10, right: 10, left: 10, bottom: 10),
              color: Colors.white,
              child: Column(
                children: <Widget>[
                  Row(
                    children: [
                      Text(
                        "*",
                        style: TextStyle(
                          fontWeight: FontWeight.bold,
                          color: Colors.red,
                        ),
                      ),
                      Text("节点类型："),
                    ],
                  ),
                  Row(
                    children: [
                      BrnRadioButton(
                        radioIndex: 0,
                        isSelected: _nodeApprovalSelectedIndex == 0,
                        child: Text(
                          "审批",
                        ),
                        onValueChangedAtIndex: (index, value) {
                          setState(() {
                            _nodeApprovalSelectedIndex = index;
                          });
                        },
                      ),
                      SizedBox(
                        width: 20,
                      ),
                      BrnRadioButton(
                        radioIndex: 1,
                        isSelected: _nodeApprovalSelectedIndex == 1,
                        child: Text(
                          "抄送",
                        ),
                        onValueChangedAtIndex: (index, value) {
                          setState(() {
                            _nodeApprovalSelectedIndex = index;
                          });
                        },
                      ),
                    ],
                  ),
                ],
              ),
            ),
            Gaps.lineLeftMargin,

            ///审批人
            Container(
              padding: EdgeInsets.only(top: 10, right: 10, left: 10, bottom: 10),
              color: Colors.white,
              child: Column(
                children: <Widget>[
                  Row(
                    children: [
                      Text(
                        "*",
                        style: TextStyle(
                          fontWeight: FontWeight.bold,
                          color: Colors.red,
                        ),
                      ),
                      Text("节点类型："),
                    ],
                  ),
                  Column(
                    children: [
                      Row(
                        children: [
                          BrnRadioButton(
                            radioIndex: 0,
                            isSelected: _nodeTypeSelectedIndex == 0,
                            child: Text(
                              "指定成员",
                            ),
                            onValueChangedAtIndex: (index, value) {
                              setState(() {
                                _nodeTypeSelectedIndex = index;
                              });
                            },
                          ),
                          SizedBox(
                            width: 10,
                          ),
                          BrnRadioButton(
                            radioIndex: 1,
                            isSelected: _nodeTypeSelectedIndex == 1,
                            child: Text(
                              "指定上级",
                            ),
                            onValueChangedAtIndex: (index, value) {
                              setState(() {
                                _nodeTypeSelectedIndex = index;
                              });
                            },
                          ),
                        ],
                      ),
                      Row(
                        children: [
                          BrnRadioButton(
                            radioIndex: 2,
                            isSelected: _nodeTypeSelectedIndex == 2,
                            child: Text(
                              "指定角色",
                            ),
                            onValueChangedAtIndex: (index, value) {
                              setState(() {
                                _nodeTypeSelectedIndex = index;
                              });
                            },
                          ),
                          SizedBox(
                            width: 10,
                          ),
                          BrnRadioButton(
                            radioIndex: 3,
                            isSelected: _nodeTypeSelectedIndex == 3,
                            child: Text(
                              "系统(自动通过)",
                            ),
                            onValueChangedAtIndex: (index, value) {
                              setState(() {
                                _nodeTypeSelectedIndex = index;
                              });
                            },
                          ),
                        ],
                      ),
                    ],
                  ),
                ],
              ),
            ),

            ///以下内容，均根据上方选择来筛选内容
            Visibility(
                visible: (_nodeTypeSelectedIndex != 3),
                child: Padding(
                  padding: EdgeInsets.only(
                    left: 12,
                    top: 10,
                    bottom: 10,
                  ),
                  child: Text(
                    '注：未匹配到成员时会该环节会自动审批通过',
                    style: TextStyle(
                      color: Colours.dark_text_gray,
                      fontSize: 10,
                    ),
                  ),
                )),

            ///这里就是选择的时候，动态显示了
            Visibility(
                visible: (_nodeTypeSelectedIndex != 3),
                child: Container(
                  padding: EdgeInsets.only(
                    left: 12,
                    right: 12,
                    top: 10,
                    bottom: 10,
                  ),
                  width: double.infinity,
                  color: Colors.white,
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Row(
                        children: [
                          Text((_nodeTypeSelectedIndex == 2) ? "指定角色" : "选择成员",
                              style: TextStyle(
                                color: Colours.base_primary_text_title,
                                fontSize: 14,
                              )),
                          Spacer(),
                          Visibility(
                              visible: (_nodeTypeSelectedIndex == 1),
                              child: Text("示例",
                                  style: TextStyle(
                                    color: Colours.base_primary,
                                    fontSize: 14,
                                  ))),
                        ],
                      ),
                      Visibility(
                          visible: (_nodeTypeSelectedIndex == 0 || _nodeTypeSelectedIndex == 1),
                          child: Text((_nodeTypeSelectedIndex == 0) ? "至少选择1位" : "以申请人的直属上级为第一级，向更高层级递",
                              style: TextStyle(
                                color: Colours.base_primary_text_hint,
                                fontSize: 12,
                              ))),
                      Visibility(visible: (_nodeTypeSelectedIndex == 0), child: AppRoveUserItemView()),
                      Visibility(
                          visible: (_nodeTypeSelectedIndex == 1 || (_nodeTypeSelectedIndex == 2)),
                          child: AppRoveMultipleItemView(
                            items: (_nodeTypeSelectedIndex == 1) ? _designatedSuperior : _roles,
                            isSingleSelection: true, // 设置为 true 表示单选，设置为 false 表示多选
                            onItemSelected: (selectedItem, selectedItems) {
                              print('Current Selected Item: $selectedItem');
                              print('All Selected Items: $selectedItems');
                            },
                          )),
                    ],
                  ),
                )),

            ///多人审批方式
            Visibility(
                visible: (_nodeTypeSelectedIndex != 3),
                child: Container(
                  margin: EdgeInsets.only(top: 10),
                  padding: EdgeInsets.only(top: 10, right: 10, left: 10, bottom: 10),
                  color: Colors.white,
                  child: Column(
                    children: <Widget>[
                      Row(
                        children: [
                          Text(
                            "*",
                            style: TextStyle(
                              fontWeight: FontWeight.bold,
                              color: Colors.red,
                            ),
                          ),
                          Text("多人审批方式："),
                        ],
                      ),
                      Column(
                        crossAxisAlignment: CrossAxisAlignment.start, // 列中的内容左对齐
                        children: [
                          Align(
                            alignment: Alignment.centerLeft,
                            child: BrnRadioButton(
                              radioIndex: 0,
                              isSelected: _singleSelectedIndex == 0,
                              child: Text(
                                "需所有成员同意(会签)",
                              ),
                              onValueChangedAtIndex: (index, value) {
                                setState(() {
                                  _singleSelectedIndex = index;
                                });
                              },
                            ),
                          ),
                          SizedBox(
                            width: 20,
                          ),
                          BrnRadioButton(
                            radioIndex: 1,
                            isSelected: _singleSelectedIndex == 1,
                            child: Text(
                              "一名成员同意即可(或签)",
                            ),
                            onValueChangedAtIndex: (index, value) {
                              setState(() {
                                _singleSelectedIndex = index;
                              });
                            },
                          ),
                        ],
                      ),
                    ],
                  ),
                )),
          ],
        ),
      ),
      bottomNavigationBar: Container(
        height: 60,
        color: Colors.white,
        padding: EdgeInsets.only(left: 16, right: 16, top: 10, bottom: 10),
        child: BrnBigMainButton(
          bgColor: Colours.base_primary_green,
          title: '完成',
          onTap: () {
            BrnToast.show('点击', context);
          },
        ),
      ),
    );
  }
}
